<template>
    <div class="large-switch" :class="{ 'switch-checked': modelValue }" @click="toggle">
        <div class="switch-handle"></div>
        <span class="switch-text checked-text">{{ checkedText }}</span>
        <span class="switch-text unchecked-text">{{ uncheckedText }}</span>
    </div>
</template>

<script setup lang="ts">

const props = defineProps({
    modelValue: {
        type: Boolean,
        default: false
    },
    checkedText: {
        type: String,
        default: '开'
    },
    uncheckedText: {
        type: String,
        default: '关'
    },
    checkedColor: {
        type: String,
        default: '#1890ff'
    },
    uncheckedColor: {
        type: String,
        default: '#ccc'
    }
})

const emit = defineEmits(['update:modelValue'])

function toggle() {
    emit('update:modelValue', !props.modelValue)
}
</script>

<style scoped>
.large-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    width: 120px;
    height: 60px;
    background-color: v-bind('props.uncheckedColor');
    ;
    border-radius: 30px;
    cursor: pointer;
    transition: background-color 0.3s;
    user-select: none;
}

.large-switch.switch-checked {
    background-color: v-bind('props.checkedColor');
}

.switch-handle {
    position: absolute;
    width: 52px;
    height: 52px;
    background-color: white;
    border-radius: 50%;
    top: 4px;
    left: 4px;
    transition: transform 0.3s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.large-switch.switch-checked .switch-handle {
    transform: translateX(60px);
}

.switch-text {
    position: absolute;
    text-align: center;
    font-size: 20px;
    font-weight: bold;
    color: white;
    pointer-events: none;
    transition: opacity 0.3s;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
}

.checked-text {
    width: 50%;
    left: 4px;
    opacity: 0;
}

.unchecked-text {
    width: 50%;
    right: 4px;
    opacity: 1;
}

.large-switch.switch-checked .checked-text {
    opacity: 1;
}

.large-switch.switch-checked .unchecked-text {
    opacity: 0;
}
</style>